package physiqueEngine.gui;

import java.awt.Component;
import java.awt.FlowLayout;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EtchedBorder;

import physiqueEngine.Refreshable;
import physiqueEngine.TestGUI;

public class StatusBar extends JPanel implements Refreshable
{
    private TestGUI window = null;
    private JLabel tickLabel = null;
    private JLabel frameLabel = null;
    private JLabel mousePosLabel = null;
    private JLabel bodyCountLabel = null;
    private JLabel memoryLabel = null;
    private JLabel worldPeriodLabel = null;
    private JLabel framePeriodLabel = null;
    private Runtime runtime = null;

    public StatusBar(TestGUI window)
    {
        this.setLayout(new FlowLayout());
        
        this.window = window;

        this.runtime = Runtime.getRuntime();

        this.tickLabel = new JLabel();
        this.frameLabel = new JLabel();
        this.mousePosLabel = new JLabel();
        this.bodyCountLabel = new JLabel();
        this.memoryLabel = new JLabel();
        this.worldPeriodLabel = new JLabel();
        this.framePeriodLabel = new JLabel();

        this.add(this.tickLabel);
        this.add(this.frameLabel);
        this.add(this.mousePosLabel);
        this.add(this.bodyCountLabel);
        this.add(this.memoryLabel);
        this.add(this.worldPeriodLabel);
        this.add(this.framePeriodLabel);
    }

    @Override
    public void refresh()
    {
        this.tickLabel.setText("tick : " + this.window.getWorldTick());
        this.frameLabel.setText("frame : " + this.window.getTickCount());
        this.mousePosLabel.setText("pos : " + this.window.getMouseLocationString());
        this.bodyCountLabel.setText("body count : " + this.window.getBodyCount());
        this.memoryLabel.setText("avalaible memory : " + this.runtime.freeMemory());
        this.worldPeriodLabel.setText("world period : " + this.window.getWorldPeriod());
        this.framePeriodLabel.setText("frame period : " + this.window.getPeriod());
    }

    public Component add(JLabel label)
    {
        label.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
        return super.add(label);
    }
}
